package com.ztt.mapper;

import com.ztt.pojo.entity.zttPurchaseDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PurchaseDetailMapper {

    @Select("select * from purchasedetails")
    public List<zttPurchaseDetail> selectAllPurchaseDetail();

    @Insert("insert into purchasedetails(Purchase_detail_id, Purchase_id, Product_id, Purchase_quantity, Product_price, Product_total_price, Notes)"
            +"values (#{purchaseDetailID}, #{purchaseID}, #{productID}, #{purchaseQuantity}, #{productPrice}, #{productTotalPrice}, #{notes})")
    public void insertPurchaseDetail(zttPurchaseDetail purchaseDetail);

    @Select("select * from purchasedetails where Purchase_detail_id = #{purchaseDetailID}")
    public zttPurchaseDetail getPurchaseDetailById(zttPurchaseDetail purchaseDetail);

    @Select("select * from purchasedetails where Product_id = #{productID}")
    public List<zttPurchaseDetail> getPurchaseDetailByProductId(zttPurchaseDetail purchaseDetail);

    @Select("select * from purchasedetails where Purchase_id = #{purchaseID}")
    public List<zttPurchaseDetail> getPurchaseDetailByPurchaseId(zttPurchaseDetail purchaseDetail);

    @Update("update purchasedetails "+
            "set Purchase_quantity = #{purchaseQuantity} , Product_price = #{productPrice} , Product_total_price = #{productTotalPrice} , Notes = #{notes} where Purchase_detail_id = #{purchaseDetailID}")
    public void updatePurchaseDetail(zttPurchaseDetail purchaseDetail);

    @Delete("delete from purchasedetails where Purchase_detail_id = #{purchaseDetailID}")
    public void deletePurchaseDetail(zttPurchaseDetail purchaseDetail);

}
